package com.ay.controller;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;


/*拦截器*/
public class MyInterceptor implements HandlerInterceptor {


    /*return ture  返回拦截器中设置的路径时 会顺序执行完 1 2 3*/

    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o) throws Exception {

        System.out.println(1);
        /*放开下面这句话程序会无限循环*/
      //  httpServletRequest.getRequestDispatcher("/test/sayhello").forward(httpServletRequest,httpServletResponse);
        return false;

    }

    @Override
    public void postHandle(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

        System.out.println(2);
    }

    @Override
    public void afterCompletion(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println(3);
    }
}
